#include <vector>

using namespace std;

class MyCircularDeque
{
private: //左边右开 贯彻到底
    vector<int> _v;
    int _capacity;
    int _front;
    int _rear;

public:
    MyCircularDeque(int k)
        : _capacity(k + 1), _front(0), _rear(0)
    {
        _v.reserve(k + 1);
    }

    bool insertFront(int value)
    {
        if (isFull())
        {
            return false;
        }
        _front = (_front - 1 + _capacity) % _capacity;
        _v[_front] = value;
        return true;
    }

    bool insertLast(int value)
    {
        if (isFull())
        {
            return false;
        }
        _v[_rear] = value;
        _rear = (_rear + 1) % _capacity;
        return true;
    }

    bool deleteFront()
    {
        if (isEmpty())
        {
            return false;
        }
        _front = (_front + 1) % _capacity;
        return true;
    }

    bool deleteLast()
    {
        if (isEmpty())
        {
            return false;
        }
        _rear = (_rear - 1 + _capacity) % _capacity;
        return true;
    }

    int getFront()
    {
        if (isEmpty())
        {
            return -1;
        }
        return _v[_front];
    }

    int getRear()
    {
        if (isEmpty())
        {
            return -1;
        }
        return _v[(_rear - 1 + _capacity) % _capacity];
    }

    bool isEmpty()
    {
        if (_rear == _front)
        {
            return true;
        }
        return false;
    }

    bool isFull()
    {
        if ((_rear + 1) % _capacity == _front)
        {
            return true;
        }
        return false;
    }
};